package com.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.manager.TestManager;
import com.model.TestModel;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("json-default")
@Results({ @Result(name = "jsonResult", type = "json") })
@Namespace("/base")
public class BaseAction extends ActionSupport{
	
	@Autowired
	private TestManager testManager;
	
	private TestModel testModel;
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public TestModel getTestModel() {
		return testModel;
	}

	public void setTestModel(TestModel testModel) {
		this.testModel = testModel;
	}

	public String add(){
		
		return "add";
	}
	
	public String addTo(){
		testManager.saveOrUpdate(testModel);
	//以下方式返回json数据
	//	dataMap.put("result", "success");
	//	return "jsonResult";
		return "success";//返回到成功页面
	}
}
